<layout name="page" />
<block name="content">
	{:widget('page_header/simple',array('name'=>'考勤规则修改'))}
	<div class="frame">
		<form method='post' id="form_data" name="form_data" enctype="multipart/form-data"  >
			<input type="hidden" id="ajax" name="ajax" value="0">
			<input type="hidden" id="opmode" name="opmode" value="edit">
			<input type="hidden" id="id" name="id" value="{$vo.id}">
			<input id="longitude" name="longitude" type="hidden" style="width:100px; margin-right:10px;" value="{$vo.longitude}"/>
			<input id="latitude" name="latitude" type="hidden" style="width:100px; margin-right:10px;" value="{$vo.latitude}" />
			<div class="frame">
				<div class="box col-12">
					
						<label class="input-label" for="name">规则名称*：</label>
						
							<input class="input" type="text" id="name" name="name" check="required" info="请输入名称"  value="{$vo.name}">
						</div>
					</div>
				</div>
				<div class="box col-12">
					
						<label class="input-label" for="sign_type">考勤类型*：</label>
						<div class="input-block col-15 x-select">
							<select id="sign_type"  name="sign_type" class="input" check="required" info="请考勤类型">
								<option value="">选择考勤类型</option>
								<option value="sign_in">签到</option>
								<option value="sign_out">签退</option>
							</select>
						</div>
					</div>
				</div>
			</div>
			<div class="frame">
				<div class="box col-12">
					
						<label class="input-label" for="name">考勤开始时间*：</label>
						<div class="input-block col-10">
							<input type="time"  class="input" name="start_time"  value="{$vo.start_time}">
						</div>
					</div>
				</div>
				<div class="box col-12">
					
						<label class="input-label" for="name">考勤结束始时间*：</label>
						<div class="input-block col-10">
							<input type="time" class="input" name="end_time"  value="{$vo.end_time}">
						</div>
					</div>
				</div>
				<div class="frame">
					<div class="box col-12">
						
							<label class="input-label" for="location">考勤地点*：</label>
							
								<input class="input"  value="{$vo.address}" type="text" id="cityName" onkeyup="theLocation()" name="address">
							</div>
						</div>
					</div>
					<div class="box col-12">
						<div class="layui-form-item  col-sm-6">
							<label class="input-label" for="name">范围*：</label>
							
								<input class="input" type="text" id="radius" name="radius"  value="{$vo.radius}">
							</div>
						</div>
					</div>
				</div>
				<div class="frame">
					<div class="box col-12">
						
							<label class="input-label" for="name">优先级*：</label>
							
								<input class="input" type="text" id="sort" name="sort" check="required" info="请输入优先级" value="{$vo.sort}">
							</div>
						</div>
					</div>
					<div class="box col-12">
						
							<label class="input-label" for="is_del">状态*：</label>
							<div class="input-block x-select">
								<select  name="is_del" id="is_del" class="input">
									<option  value="0">启用</option>
									<option value="1">禁用</option>
								</select>
							</div>
						</div>
					</div>
					<div  class="layui-form-item" id="map" >
						<div id="allmap" style="margin-left:10%; width:85%;height:500px"></div>
					</div>
					
						
							<a class="btn btn-normal" onclick="save()">保存</a>
							<a class="btn btn-return"onclick="go_return_url();">取消</a>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
</block>
<block name="js">
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=2LoqyAU1SXDkMeI5f4ToV0VO"></script>
	<script type="text/javascript">
		layui.use(['global'], function() {
		var $=layui.jquery;
		var map=new BMap.Map("allmap");
		map.enableScrollWheelZoom();
		//启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom();
		var longitude=document.getElementById("longitude").value;
		var latitude=document.getElementById("latitude").value;
		//经度
		var point=new BMap.Point(longitude,latitude);
		map.centerAndZoom(point,15);
		addMarker(point);
		set_val('sign_type','{$vo.sign_type}');
		set_val('is_del','{$vo.is_del}');
		//刷新select选择框渲染
		theLocation();
		$("#btn_save").on('click', function() {
		send_form("form_data","{:url('save')}",'', function(ret) {
		});
		});
		function addMarker(point) {
		var marker=new BMap.Marker(point);
		map.addOverlay(marker);
		marker.enableDragging();
		marker.addEventListener("dragend", function(e) {
		//alert("当前位置：" + e.point.lng + ", " + e.point.lat);
		document.getElementById("longitude").value=e.point.lng;
		//经度
		document.getElementById("latitude").value=e.point.lat;
		});
		};
		function theLocation() {
		map.enableScrollWheelZoom();
		//启用滚轮放大缩小，默认禁用
		map.enableContinuousZoom();
		//启用地图惯性拖拽，默认禁用
		//单击获取点击的经纬度
		map.addEventListener("click", function(e) {
		delPoint();
		document.getElementById("longitude").value=e.point.lng;
		//经度
		document.getElementById("latitude").value=e.point.lat;
		//纬度
		var new_point=new BMap.Point(e.point.lng,e.point.lat);
		var marker=new BMap.Marker(new_point);
		// 创建标注
		map.addOverlay(marker);
		marker.enableDragging();
		marker.addEventListener("dragend", function(e) {
		//alert("当前位置：" + e.point.lng + ", " + e.point.lat);
		document.getElementById("longitude").value=e.point.lng;
		//经度
		document.getElementById("latitude").value=e.point.lat;
		});
		});
		var city=document.getElementById("cityName").value;
		if(city!="") {
		map.centerAndZoom(city,18);
		// 用城市名设置地图中心点
		}
		};
		function delPoint() {
		var allOverlay=map.getOverlays();
		for(var i=0;i<allOverlay.length;i++) {
		map.removeOverlay(allOverlay[i]);
		}
		};
		});
	</script>
</block>